import request from "@/utils/request";
import type { TradeMarkResponseData, TradeMark } from "../trademark/type";
import type { ResponseData } from "@/api/user/type";
import type {
  SpuData,
  SpuImage,
  SaleAttrValue,
  AllSaleAttr,
  SkuData,
} from "./type";
enum API {
  HASSPUDATA_URL = "/admin/product/", //获取已有sku数据的API
  ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList", //获取全部SPU品牌的API
  SPUIMAGE_URL = "/admin/product/spuImageList/", //获取某个SPU下售卖商品图片的API
  SPUHASSALE_URL = "/admin/product/spuSaleAttrList/", //获取某一SPU下已有的销售属性的API
  ALLSALE_URL = "/admin/product/baseSaleAttrList", //获取全部销售属性【颜色 版本 尺码】
  ADDSPU_URL = "/admin/product/saveSpuInfo", //添加SPU
  UPDATESPU_URL = "/admin/product/updateSpuInfo", //修改SPU
  ADDSKU_URL = "/admin/product/saveSkuInfo", //追加一个新增的SKU地址
  SKUINFO_URL = "/admin/product/findBySpuId/", //查看某一个已有的SPU下全部售卖的商品
  DELETESPU_URL = "/admin/product/deleteSpu/", //删除已有的SPU
}
//获取已有sku数据的方法
export const reqHasSpuData = (
  page: number | string,
  limit: number | string,
  category3Id: number | string
) => {
  return request.get<any, ResponseData<TradeMarkResponseData<SpuData>>>(
    `${API.HASSPUDATA_URL}${page}/${limit}?category3Id=${category3Id}`
  );
};
//获取全部品牌的数据的方法
export const reqAllTrademark = () => {
  return request.get<any, ResponseData<TradeMark[]>>(API.ALLTRADEMARK_URL);
};
//获取某个SPU下售卖商品图片地址的方法
export const reqSpuImage = (spuId: number | string) => {
  return request.get<any, ResponseData<SpuImage[]>>(
    `${API.SPUIMAGE_URL}${spuId}`
  );
};
// 获取某一个已有spu拥有多少个销售属性的方法
export const reqSpuHasSale = (spuId: number | string) => {
  return request.get<any, ResponseData<SaleAttrValue[]>>(
    API.SPUHASSALE_URL + `${spuId}`
  );
};
//获取全部销售属性【颜色 版本 尺码】
export const reqAllSale = () => {
  return request.get<any, ResponseData<AllSaleAttr[]>>(API.ALLSALE_URL);
};
//添加｜修改SPU
export const reqAddOrUpdateSpu = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data);
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data);
  }
};
//添加一个SKU
export const reqAddSkuData = (data: SkuData) => {
  return request.post<any, any>(API.ADDSKU_URL, data);
};
//获取SKU数据
export const reqSkuData = (spuId: number | string) => {
  return request.get<any, ResponseData<SkuData[]>>(
    API.SKUINFO_URL + `${spuId}`
  );
};
//删除已有的SPU
export const reqDeleteSpu = (spuId: number | string) => {
  return request.delete<any, any>(API.DELETESPU_URL + `${spuId}`);
};
